{% if not mode_js %}
<!DOCTYPE html>
<html>

<head>
<title>Collaborative Disaster Recovery Work Order System: Enter a Work Order.</title>
<link href="/stylesheets/form.css?v={{version}}" rel="stylesheet">
<link href="/stylesheets/default.css?v={{version}}" rel="stylesheet">
 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>          

<!-- <link href="/stylesheets/popup_radio_form.css" rel="stylesheet"> -->

  <link rel="stylesheet" href="/closure/css/autocomplete.css?v={{version}}">

{% if in_prod %}
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCv5oq0DwffOWKYK_tZBbOFguIcL22eF3c&v=3.exp&sensor=false"></script>
{% else %}
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
{% endif %}
{% if not_compiled %}
<script src="/closure/goog/base.js?v={{version}}"></script>
<script src="/javascript/deps.js?v={{version}}"></script>
<script type="text/javascript">
goog.require("sandy.form");
</script>
{% else %}
<script src="/javascript/compiled_form.js?v={{version}}">
{% endif %}
</script>
<script>
{% if post_json %}
$(function(){
var post_json = {{post_json}};
var oFormObject = document.forms['form'];

Object.keys(post_json).forEach(function(key) {
    var this_element = document.getElementById(key);
    if (key == "priority") {
      var which_button = null;
      if (post_json[key] == "5") {
	which_button = "0";
      }
      if (post_json[key] == "4") {
	which_button = "1";
      }
      if (post_json[key] == "3") {
	which_button = "2";
      }
      if (post_json[key] == "2") {
	which_button = "3";
      }
      if (post_json[key] == "1") {
	which_button = "4";
      }
      
      var new_key = "priority-" + which_button;
      this_element = document.getElementById(new_key);
    }
    var type = null;
    try
    {
      var type = this_element.type;	
      console.log("TYPE: " + type);
      if (type == "text") {
	this_element.value = post_json[key];
      }
      if (type == "textarea") {
	this_element.value = post_json[key];
      }
      
      if (type.indexOf("select") !== -1) {
	this_element.value = post_json[key];
	console.log("SELECT!!!!!!!!!!!!");
      }
      if (type == "checkbox") {
	this_element.checked = true;
      }
      
      if (type == "radio") {
	this_element.checked = true;
      }

    }
  catch(err)
    {
      console.log("ERROR, ELEMENT = " + key + err);
      
    }

    console.log(key, post_json[key]);
//     if (key == "name") {
//        var the_element = document.getElementById(key);
//        the_element.value = post_json[key];
//     }
});
})

{% endif %}
</script>
</head>

<body onload="sandy.form.Initialize()">

<div id="form_background">
<div id="form">
{% if delete %}
<div class=delete_form>
  <form method=POST action="{{delete_post_url}}">
  <input type=hidden name=_id value="{{id}}">
  <input type=submit value="Permanently delete this site" class=delete_button>
  (this cannot be undone)
  </form>
</div>{# end delete_form #}
{% endif %}
<form method="POST" action="{{page}}">
{% endif %} {# not mode_js #}
<input type="hidden" name="event_name" value="{{event_name}}" />

{% if similar_site %}
  <section id="errors">
    <h1>Possible Duplicate</h1>
    <p>It looks like {{ similar_site.name }} ({{ similar_site.address }}) is already in the system.</p>
    <p><a href="/edit?id={{ similar_site.key().id() }}" target="_new_duplicate">Click here to open exisiting work order (in a new tab)</a></p>
    <input type="submit" onclick="document.getElementById('ignore_similar').checked=true;" value="Ignore &amp; Save">
  </section>
{% endif %}

{% if message %}
  <div class="form_message">
    {% if message_url %}
      <a href="{{ message_url }}">{{ message }}</a>
    {% else %}
      {{ message }}
    {% endif %}
  </div>
{% endif %}

{% if errors %}
<section id="errors">
  <header>The submission had errors</header>
  <article>
    <ul>
    {% for k in errors %}
      <li class="error">
        {% for e in errors[k] %}
          {{k}}: {{e}}
        {% endfor %}
      </li>
    {% endfor %}
    </ul>
  <article>
</section>
{% endif %}
<div class="QuestionHeading">
The {{event_name}} Waiting List will alert volunteer organizations in your area that you need assistance. As the need is so great, we cannot guarantee that you will be helped, and we do not know how long you might need to wait before an organization helps. We are working as hard as we can.
</div>

<div id="similars"></div>

{{ single_site }}

{% if id %}
<input type="hidden" name="_id" value="{{id}}">
{% endif %}
{% if not mode_js %}

{% if not delete %}
{% if id %}

{% else %}

<br>

{% endif %}
{% endif %}
</form>
</div>
</div>
{{ logout }}

<div id="map_canvas"></div>
<div id="wrapper"></div>

</body>
</html>
{% endif %} {# not mode_js #}
